package sort_algorithms;

import main.SortDemo;

import datastructures.Datum;
import datastructures.Status;

/**
 * Simple random "sort" algorithm
 * 
 * @author kf6kjg
 * 
 */
public class RandomSort extends AbstractSorter {
  int   left  = 0;
  
  int   right = 1;
  
  Datum datum_left;
  
  Datum datum_right;
  
  /*
   * (non-Javadoc)
   * 
   * @see sort_algorithms.ISorter#step()
   */
  @Override
  public void step() {
    datum_left.status = datum_right.status = Status.DEFAULT;
    
    SortDemo.data.setElementAt(datum_right, left);
    SortDemo.data.setElementAt(datum_left, right);
    
    left = (int) (Math.random() * SortDemo.data.size());
    right = (int) (Math.random() * SortDemo.data.size());
    
    datum_left = SortDemo.data.get(left);
    datum_right = SortDemo.data.get(right);
    ;
    
    datum_left.status = Status.COMPARE_LEFT;
    datum_right.status = Status.COMPARE_RIGHT;
  }
  
  /*
   * (non-Javadoc)
   * 
   * @see sort_algorithms.AbstractSorter#isSorted()
   */
  @Override
  public boolean isSorted() {
    return false;
  }
  
  /*
   * (non-Javadoc)
   * 
   * @see sort_algorithms.AbstractSorter#getName()
   */
  @Override
  public String getName() {
    return "Random Sort";
  }
  
  /*
   * (non-Javadoc)
   * 
   * @see sort_algorithms.AbstractSorter#reset()
   */
  @Override
  public void reset() {
    datum_left = SortDemo.data.get(left);
    datum_right = SortDemo.data.get(right);
  }
}
